{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='../../plugin/lingze/template/web/common_nav'}
    {if $method == "lingze_main"}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$page_total}</div>
        <div class="panel-body">
            <form id = "myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="r" value="lingze" />
                <input type="hidden" name="do" value="web" />
                <div class="form-group">
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <a href="{php echo createWebUrlPlugin('lingze.add',array('themeid'=>$themeid));}" class="btn btn-primary">添加奖项</a>
                    </div>
                    {if count($themelist)>1 }
                    <div class="col-xs-12 col-sm-2 col-md-2">
                        <select onchange="submitForm();" class="form-control" name="themeid">
                            {loop $themelist $row}
                            <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                            {/loop}
                        </select>
                    </div>
                    {else}
                    <input type="hidden" name="themeid" value="{$themeid}" />
                    {/if}
                </div>
            </form>
        </div>
    </div>
    {/if}


    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 120px">奖品图</th>
                        <th style="width: 100px">奖品名称</th>
                        <th style="width: 80px">宝箱名称</th>
                        <th style="width: 100px">关卡</th>
                        <th style="width: 100px">操作</th>
                        <th style="width: 100px">操作次数</th>
                        <th style="width: 120px">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $item}
                    <tr>
                        <td>{$item['lc_id']}</td>
                        <td><a href="{php echo tomedia($item['small_img']);}"  target="_blank" title="查看原图"><img src="{php echo tomedia($item['small_img']);}" style="width: 40px;height: 40px;padding: 1px;"></a></td>
                        <td>{$item['chest_name']}</td>
                        <td>{$item['box_name']}</td>
                        <td>第{$item['level_sort']}关</td>
                        <td>
                            {if $item['type']=='share'}
                            <span class="label label-info ">分享好友或群聊</span>
                            {elseif $item['type']=='friend_view'}
                            <span class="label label-danger">好友到访</span>
                            {else}
                            <span class="label label-success">好友下单</span>
                            {/if}
                        </td>
                        <td>{$item['type_num']}次</td>
                        <td>
                            <a class="btn btn-primary btn-sm" style="width: 35px" onclick="changeOrDelItem(this)" data-type="edit"
                               data-edit-url="{php echo createWebUrlPlugin('lingze.edit',array('themeid'=>$themeid,'lc_id'=>$item['lc_id']));}"
                               data-themeid="{$themeid}" data-id="{$item['p_id']}"  title="修改奖品信息" data-toggle="tooltip" data-placement="top"><i class="fa fa-pencil-square-o"> </i></a>
                            <a class="btn btn-danger btn-sm" style="width: 35px" onclick="changeOrDelItem(this)" data-type="del"
                               data-edit-url="" data-themeid="{$themeid}" data-id="{$item['lc_id']}" title="删除奖品" data-toggle="tooltip" data-placement="top"><i class="fa fa-times"> </i></a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</div>

{$pager}
<script type="text/javascript">
    function submitForm(){
        var form = document.getElementById("myform");
        form.submit();
    }
    $(document).ready(
    );
    // 修改、删除奖品
    function changeOrDelItem(e) {
        let type = e.getAttribute("data-type");
        let lc_id = e.getAttribute("data-id");
        let themeid = e.getAttribute("data-themeid");
        let redirectUrl = e.getAttribute("data-edit-url");
        let postUrl ="";
        if (type=='edit'){
            window.location.href = redirectUrl;
        }
        if (type=='del'){
            postUrl = "{php echo createWebUrlPlugin('lingze.delete');}";
            layer.msg('您确定删除该奖品吗？',{
                btn:['确定','取消'],
                yes:function (index) {
                    $.ajax({
                        url:postUrl,
                        dataType:'json',
                        method:'post',
                        data: {lc_id:lc_id,themeid:themeid},
                        success:function (e) {
                            let status = e.status;
                            let result = e.result;
                            if (status!=1){
                                layer.msg(result.msg)
                            }else{
                                layer.msg(result.msg);
                                location.reload();
                            }
                        },
                        fail:function (err) {
                            console.log(err)
                        }
                    });
                }
            });
        }
    }
</script>
